package com.ytjj.qmyx.supplychain.api.controller;

import com.kuaidi100.sdk.request.SupplyChainBrandRequest;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.mapper.entity.YxSupplyChainBrand;
import com.ytjj.qmyx.supplychain.service.SupplyChainBrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 供应链商品品牌管理
 */
@Slf4j
@RestController
@RequestMapping("/supplyChainBrand")
public class SupplyChainBrandController {

    @Autowired
    private SupplyChainBrandService supplyChainBrandService;

    /**
     * 查询供应链商品品牌
     *
     * @return
     */
    @PostMapping("/list")
    public CommonResult list(@RequestBody SupplyChainBrandRequest request) {
        return CommonResult.success(supplyChainBrandService.list(request));
    }

    /**
     * 查询所有供应链商品品牌
     *
     * @return
     */
    @GetMapping("/all")
    public CommonResult all(@RequestParam(required = false) String chineseName) {
        return supplyChainBrandService.all(chineseName);
    }

    @PostMapping("/selectByIds")
    public List<YxSupplyChainBrand> selectByIds(@RequestBody SupplyChainBrandRequest request) {
        return supplyChainBrandService.selectByIds(request);
    }

    /**
     * 新增或修改
     *
     * @return
     */
    @PostMapping("/addAndUpdate")
    public CommonResult addAndUpdate(@RequestBody YxSupplyChainBrand yxSupplyChainBrand) {
        Integer i = supplyChainBrandService.addAndUpdate(yxSupplyChainBrand);
        return i > 0 ? CommonResult.success() : CommonResult.failed();
    }
}
